def call(String jobName, String jarPath, String giturl) {

    pipeline {
        agent any

        environment {
            APP_NAME = "${jobName}"
            JAR_PATH = "${env.WORKSPACE}/${jarPath}"
        }

        tools {
        jdk 'jdk1.8'
        maven 'mvn-3.9.11'
    }
    options {
         // 保留最新的50个构建记录
        buildDiscarder(logRotator(numToKeepStr: '50'))
        // 不允许并发构建
        disableConcurrentBuilds()
    }
    
    stages {
        
        stage('1.拉取代码') {
            steps {
                script {
                    git branch: "main", credentialsId: 'https', url:"https://github.com/xianyu-zwx/temp-springboot-project.git"
                }
            }
        }
        stage('2.编译') {
            steps {
                sh "mvn package -Dmaven.test.skip=true"
            }
        }
        stage('3.发布') {
            steps {
                dir('/opt/playbook') {
                    ansiColor('xterm') {
                        ansiblePlaybook(
                            playbook: 'deploy.yml',
                            inventory: 'hosts',
                            colorized: true,
                            extraVars: [
                                app : [value: "${env.JOB_NAME}",hidden: false],
                                jar_path : [value: "${env.JAR_PATH}",hidden: false]
                                ]
                                )
                    }
                }
            }
        }
    }
}